package com.thumbs.auth.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.thumbs.auth.entity.User;
import com.thumbs.auth.mapper.UserMapper;
import com.thumbs.auth.service.UserService;
import com.thumbs.common.enums.ErrorCode;
import com.thumbs.common.response.BaseResponse;
import com.thumbs.common.utils.ResultUtils;
import org.springframework.stereotype.Service;

/**
* @author lizihang
* @description 针对表【user】的数据库操作Service实现
* @createDate 2025-04-29 16:32:26
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService {

    /**
     * 登录
     * @param username 用户名
     * @return BaseResponse<User>
     */
    @Override
    public BaseResponse login(String username) {
        User user = this.getOne(new QueryWrapper<User>().eq("username", username));
        if (user == null) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_USER);
        }
        StpUtil.login(user.getId());
        return ResultUtils.success(user);
    }
}




